<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}
if($_POST['sub']!=''){
    $id=empty($_POST['id'])?0:(int)$_POST['id'];
	unset($_POST['id']);
	unset($_POST['sub']);
    if(empty($_POST["shop_id"])){
        
        jumpajax('300','名厨(名店)一项不能为空!','');
    }
    if(empty($_POST["title"])){
        
        jumpajax('300','菜品名称不能为空!','');
    }
    if(empty($_POST["pcate"])){
        
        jumpajax('300','菜品分类不能为空!','');
    }
    if(empty($_POST["productprice"])){
        
        jumpajax('300','菜品价格不能为空!','');
    }
    if(empty($_POST["basicprice"])){
        
        jumpajax('300','菜品成本价格不能为空!','');
    }

    

    $status=intval($_REQUEST["status"]);
    $p=0;
    $imglist=array();
    $thumb_url="";
    while($p<6){
        $flp=trim($_POST["imgs".$p."_fileName"]);
        if(!empty($flp)){
            $imglist[]=$flp;
        }
        
        $p++;
    }
    if(!empty($imglist)){
        $thumb_url=implode("|",$imglist);
        $_POST["imgs0_fileName"]=$imglist[0]; 
    }
        
    
	$data=array('title'=>trim($_POST["title"]),
    'productprice'=>trim($_POST["productprice"]),
    'basicprice'=>$_POST["basicprice"],
    'thumb'=>trim($_POST["imgs0_fileName"]),
    'thumb_url'=>$thumb_url,
    'displayorder'=>intval($_POST["listorder"]),
    'isindex'=>intval($_POST["isindex"]),  
    'createtime'=>time(),
    'productsn'=>'',
    'content'=>trim($_POST["content"]),
    'status'=>$status,
    'weid'=>$_SESSION['EZ_Admin']['id'],
    'pcate'=>intval($_POST["pcate"]),
    "title_en"=>mysql_escape_string($_POST["title_en"]),
    "shop_id" => trim($_POST["shop_id"]),
    
    );
    $metlist=array();
   
 	if($id==0){
        $id=$ezhand->insert("shopping3_goods",$data);
		jumpajax('200','菜品保存成功','page362','closeCurrent');
	}else{

        $ezhand->update("shopping3_goods",$data,'id="'.$id.'"');          
		jumpajax('200','菜品修改成功','page362','closeCurrent');
	}
}else{
	$id=empty($_GET['id'])?0:(int)$_GET['id'];
    

    $catlist[0]="选择菜品分类";
    $catlisttemp=$ezhand->get_cattree2(0,"shopping3_category");
    
    $cheflisttemp=$ezhand->get_chefbyid("shopping3_chef");
    $cheflist=array("0"=>"请选择");
    foreach($cheflisttemp as $val){
        $sid=$val["id"];
        $cheflist[$sid]=$val["name"];  

    }
    
    if($id==0){
	    $row=array();
        $row["status"]=1;
	}else{
	   
	    $row=$ezhand->select("shopping3_goods",'*','id="'.$id.'"');
        $imagelist=explode("|",$row["thumb_url"]);
	}
}
?>